﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace HTMLPackage
{
    class Program
    {
        //linkPattern describes a valid link in a string
        static string linkPattern = "<a\\shref\\s*=\\s*(?:\"(?<1>[^\"]*)\"|(?<1>\\S+))";
        static string framePattern = "<FRAME\\ssrc\\s*=\\s*(?:\"(?<1>[^\"]*)\"|(?<1>\\S+))";


        static void Main(string[] args)
        {
            Console.WriteLine(IsValidLink("<frame src=\"frame_a.htm\" />"));

            string doc = "Dette er en link: <a href=\"overnatning/overnatning.html\"> og det er det her også <a href=\"English/HomeEnglish.html\">.";

               
            List<string> linkList = GetLinkList(doc);
            Console.WriteLine("Number of links retrieved: " + linkList.Count);
            Console.WriteLine();
            foreach (string lnk in linkList)
                Console.WriteLine(lnk);


            Console.ReadLine();
            Console.WriteLine(IsValidLink(@"+1.0E+8"));
            Console.ReadLine();
        }

        static List<string> GetLinkList(string doc)
        {
            List<string> returnList = new List<string>();
            MatchCollection mc = Regex.Matches(doc, linkPattern);
            Console.WriteLine("Number of links found: " + mc.Count);
            Console.ReadLine();
            foreach (Match match in mc)
            {
                returnList.Add(match.Value);
            }

            Console.ReadLine();
            return returnList;
        }

        static bool IsValidLink(string strLink)
        {
            return Regex.IsMatch(strLink, framePattern);
        }
    }
}
